package com.tgm.controller;


import com.tgm.domain.common.Result;
import com.tgm.domain.dto.StatisticsPieDTO;
import com.tgm.domain.dto.StatisticsTrendDTO;
import com.tgm.domain.vo.StatisticsVO;
import com.tgm.service.ConsumptionRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
 * 报表controller
 */
@RestController
@RequestMapping("/statistics")
public class ReportController {
    @Autowired
    private ConsumptionRecordService consumptionRecordService;

    @GetMapping("/trend")
    public Result trend(StatisticsTrendDTO statisticsTrendDTO){
        System.out.println("请求参数："+statisticsTrendDTO);
        try {
            StatisticsVO statisticsVO = consumptionRecordService.statisticsTrend(statisticsTrendDTO);
            return Result.success(statisticsVO);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败：" + e.getMessage());
        }
    }

    @GetMapping("/pie")
    public Result pie(StatisticsPieDTO statisticsPieDTO){
        try {
            StatisticsVO  list = consumptionRecordService.statisticsPie(statisticsPieDTO);
            return Result.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败：" + e.getMessage());
        }
    }
}